<?php
$server = new soap_server;
$namespace = 'uri:menu';

$server->configureWSDL('menuServer',$namespace,$location);
$server->wsdl->schemaTargetNamespace = $namespace;


$server->wsdl->addComplexType
(
    'MenuItem',
    'complexType',
    'struct',
    'all',
    '',
    array
    (
        'id' => array('name'=>'id','type'=>'xsd:int'),
        'link' => array('name'=>'link','type'=>'xsd:string'),
        'name' => array('name'=>'name','type'=>'xsd:string'),
		'last_modified' => array('name'=>'last_modified','type'=>'xsd:string'),
    )
);

$server->wsdl->addComplexType
(
    'MenuItemArray',
    'complexType',
    'array',
    '',
    'SOAP-ENC:Array',
    array(),
    array(
        array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:MenuItem[]')
    ),
    'tns:MenuItem'
);

$server->register('getMenu',array(),array('ret' => 'tns:MenuItemArray'),$namespace,$namespace . '/get','rpc','encoded');

function getMenu()
{
	global $bd;
	$sql = 'SELECT * FROM ' . TABLE_PREFIX . 'menu';

	$menu = array();

	for ($bd->QueryObj($sql);$bd->data;$bd->NextObj())
	{
		$menu[] = array('id' => $bd->data->id, 'name' => $bd->data->name, 'link' => $bd->data->href, 'last_modified'=>$bd->data->create_date);
	}
	return $menu;
}

if (substr_count($_SERVER['REQUEST_URI'],'wsdl')) //hack ... but it`s work
{
	header("Content-Type: text/xml; charset=ISO-8859-1\r\n");
	die($server->wsdl->serialize(false));
}


$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA); 
?>